#!/usr/bin/perl
use strict;
use modules::encode;
package nsrecover;

sub nsrecover {
    my ($dbh,$remote,$input,$nsnum) = @_;
	my $sth=$dbh->prepare("SELECT nick,auth FROM ninfo where num = '$$input[0]' AND code = '".encode::encode($$input[0])."';");
	$sth->execute;
	my @tmp = $sth->fetchrow_array;
    if ($$input[4] eq "") {
	print $remote "$nsnum O $$input[0] :Syntax: RECOVER <Rnick>\n";
    }
    elsif (lc($tmp[1]) ne lc($$input[4])) {
	print $remote "$nsnum O $$input[0] :You have to be identified as $$input[4] before using this command.\n";
    }
	elsif (lc($tmp[0]) eq lc($$input[4])) {
	    print $remote "$nsnum O $$input[0] :You wouldnt want to kill  yourself right?\n";
	}
    else {
	$sth=$dbh->prepare("SELECT num FROM ninfo WHERE nick = '$$input[4]';");
	$sth->execute;
	my $kill = $sth->fetchrow_array;	
	$sth=$dbh->prepare("DELETE FROM ninfo WHERE nick = '$$input[4]';");
	$sth->execute;
	print $remote "$nsnum O $$input[0] :You may change your nick to $$input[4] now.\n";
	print $remote "$nsnum D $kill :NS RECOVER COMMAND USED.\n";

    }
}
1;
